
var app = getApp();
var ApiUrl = app.globalData.ApiUrl;
var mph = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    point: 0,
    predepoit: 0,
    dikou_money:'-',
    available_rc_balance: 0,
    redpacket: 0,
    user_info:{},
    user_asset:{
      predepoit: '-',
      point: '-',
      voucher: '-',
    },
    voucher: 0,
    vip_flag_bool:false,
    article_id:42,
    my_order_nav_data:[
      {
        id:1,
        u_name: 'state_new',
        img_url:"/image/daizhifu.png",
        text:'待支付'
      },{
        id: 2,
        u_name: 'daipeisong',
        img_url: "/image/baozhuang.png",
        text: '待配送'
      }, {
        id: 3,
        u_name: 'state_send',
        img_url: "/image/navicon-chps.png",
        text: '配送中'
      }, {
        id: 4,
        u_name: 'state_noeval',
        img_url: "/image/daipingjia.png",
        text: '待评价'
      }
    ]
  
  },
  go_message_list(){
    wx.navigateTo({
      url:"/pages/message_list/message_list"
    })
  },
  go_my_balance() {
    wx.navigateTo({
      url: "/pages/my_balance/my_balance"
    })
  },
  go_memberVIP(){
    wx.navigateTo({
      url: "/pages/memberVIP/memberVIP"
    })
  },
  go_my_order(e){
    let name = e.currentTarget.dataset.name;
//console.log(e);
    wx.navigateTo({
      url: "/pages/my_order/my_order?name="+name
    })
  },
  go_order_after_sale(){
    wx.navigateTo({
      url: "/pages/order_after_sale/order_after_sale"
    })
  },
  // go_Addressinfor(){
  //   wx.navigateTo({
  //     url: "/pages/adressInfo/adressInfo"
  //   })
  // },
  //获取余额/红包/券/牧草积分
  add_my_asset(obj) {

  },
  //我的商城
  my_info() {
    // wx.showToast({ title: '加载中', icon: 'loading', duration: 10000 });
            let that = this;

            //获得我的信息
            var url = 'index.php?act=member_index';
            mph.postRequest(url, {},function(res){
              console.log('我的商城:==>', res.data.datas.member_info);
                if(res.data.code==200){
                  that.setData({
                    user_info:res.data.datas.member_info
                  })
                }else{
                  mph.showErrorTost(res.msg);
                }
            })

            //获取用户的资金情况
            var url = 'index.php?act=member_index&op=my_asset';
            mph.postRequest(url, {},function(res){
              console.log('获取用户的资金情况:==>', res);
                if(res.data.code==200){

                  if (res.data.datas.predepoit >= 10000) {
                    res.data.datas.predepoit = '¥'+parseInt(parseInt(res.data.datas.predepoit) / 10000) + '万';
                  }
                  if (res.data.datas.point >= 10000) {
                    res.data.datas.point = parseInt(parseInt(res.data.datas.point) / 10000) + '万';
                  }
                  if (res.data.datas.voucher >= 10000) {
                    res.data.datas.voucher = parseInt(parseInt(res.data.datas.voucher) / 10000) + '万';
                  }

                  that.setData({
                    user_asset: res.data.datas
                  })
                  // wx.hideToast();
                }else{
                  mph.showErrorTost(res.msg);
                }
            })
  },
  get_replace_money_info() {
    //获取用户的抵扣金
    let k = wx.getStorageSync('key');
    let that = this;
    wx.request({
      url: ApiUrl + "/index.php?act=other_member&op=get_replace_money_info",
      data: { key: k },
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'post',
      success: function (result) {
        //console.log(result);
        if (result.statusCode == 200) {
          if (result.data.code == 200) {
            console.log('获取用户的抵扣金:==>',result.data.datas.info.money);
            let res = result.data.datas.info.money;

            if (res>=10000){
              res = parseInt(res/10000)+'万';
            }

            that.setData({
              dikou_money: res
            })
          }
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that =this;
    this.my_info();
    this.get_replace_money_info();
    //index.php?act=vipopen&op=vip_flag_list
    var url = 'index.php?act=vipopen&op=vip_flag_list';
    let k = wx.getStorageSync('key');

    let list = { act: 'vipopen', op:'vip_flag_list',key:k};
    mph.postRequest(url, list, function (res) {
      // res.data.datas.flag_list/
      if(res.data.code==200){
        console.log(res.data.datas);
        if (!res.data.datas.flag_list) {
          that.setData({
            vip_flag_bool: false
          })

        }
        //我的临时会员码本地存储
        wx.setStorageSync('vip_lists', res.data.datas.flag_list);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.my_info() 
    this.get_replace_money_info();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})